﻿SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON

GO


CREATE TABLE dbo.bht_Versions
(
	Feature nvarchar(400) NOT NULL,
	DbVersion nvarchar(100) NOT NULL
)  ON [PRIMARY]
GO


CREATE PROCEDURE bhp_VersionsGet
(
	@FunctionalityName			NVARCHAR(400)
)
AS
	IF EXISTS (SELECT 1 FROM bht_Versions WHERE Feature = @FunctionalityName)
		SELECT DbVersion FROM bht_Versions WHERE Feature = @FunctionalityName
	ELSE
		SELECT '' AS DbVersion

GO


CREATE PROCEDURE bhp_VersionsSet
(
	@FunctionalityName			NVARCHAR(400),
	@DbVersion			NVARCHAR(100)
)
AS
	IF EXISTS (SELECT 1 FROM bht_Versions WHERE Feature = @FunctionalityName)
		UPDATE
			bht_Versions 
		SET
			DbVersion		= @DbVersion
		WHERE 
			Feature			= @FunctionalityName
	ELSE
		INSERT INTO bht_Versions		(Feature,		DbVersion)
						VALUES							(@FunctionalityName, @DbVersion)

GO
